package com.ifast.job.jobs;

import java.util.List;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.ifast.oupei.domain.MatchDO;
import com.ifast.oupei.service.MatchService;
import com.ifast.oupei.util.HTMLParserUtil;

@Component
public class GetScoreJob implements Job {
	@Autowired
	MatchService matchService;

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		// 获取目前时间之前的所有没有比分的比赛的比分，如果获取不了，删除之（代表补赛）
		List<MatchDO> matchList = matchService.getScoreList();
		for (MatchDO match : matchList) {
			try {
				if ("-".equals(HTMLParserUtil.getScore(match.getTicketsId()))) {
					// 不能够获取比分，删除之
					matchService.delete(new EntityWrapper<MatchDO>().where("id = {0}", match.getId()));
				} else {
					String score = HTMLParserUtil.getScore(match.getTicketsId());
					match.setScore(score);// 获取比分
					match.setResult(HTMLParserUtil.getResult(score));//获取结果
					matchService.updateById(match);// 更新比分
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
